package com.bb.Controllers;

import java.util.HashMap;
import java.util.Map;

import com.bb.pojo.User;
import com.bb.services.impl.UserServiceImpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{
	private UserServiceImpl userServiceImpl = new UserServiceImpl();
	private User user; 
//	用户的注册
	public String getRegister(){
		System.out.println("接收注册数据"+user);
		int userregisters = userServiceImpl.userregisters(user);
		System.out.println(userregisters);
		if(userregisters>0){
			return "dealregister";
		}else{
			return "errorregister";
		}
		
	}
//用户登录
	public String getLogin(){
		System.out.println("接收登录数据"+user);
		Map map = new HashMap();
		map.put("u_name", user.getU_name());
		map.put("u_pass", user.getU_pass());
		int userlogin = userServiceImpl.userlogin(map);
		if(userlogin >0){
			Map<String, Object> session = ActionContext.getContext().getSession();
			session.put("u_name", user.getU_name());
			return "loginSuccess";
		}else{
			return "loginError";
		}
	}
	
	public String intoUserRegister(){
		System.out.println("进入用户注册页面");
		return "userregister";
	}
	
	public String intoUserLogin(){
		System.out.println("进入用户登录页面");
		return "userlogin";
	}
	
	
	
	
	
	
	
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
}
